package cn.tedu.mall.book.controller;

import cn.tedu.mall.book.pojo.dto.AdminLoginDTO;
import cn.tedu.mall.book.service.IAdminService;
import cn.tedu.mall.book.web.JsonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @author zxjun
 * @date 2022/6/7 20:59
 */
@RestController
@RequestMapping(value = "/admins", produces = "application/json; charset=utf-8")
public class AdminController {

    @Autowired
    IAdminService adminService;

    @PostMapping("/login")
    public JsonResult login(@RequestBody AdminLoginDTO adminLoginDTO, HttpSession session){
        System.out.println("adminLoginDTO = " + adminLoginDTO + ", session = " + session);
        adminService.login(adminLoginDTO,session);
        return JsonResult.ok();

    }

    @GetMapping("/logout")
    public JsonResult logout(HttpSession session){
        //把登录成功时的数据删除
        session.removeAttribute("admin");
        return JsonResult.ok();
    }
}
